<template>
  <view class="container">
    <view class="list">
      <view class="listitem" v-for="item in list" :key="item.id" @click="goorderdetail(item)">
        <view style="display: flex; align-items: center; font-family: PingFang SC, PingFang SC; font-weight: bold; font-size: 28rpx; color: #333333">
          <view>{{ item.name }}</view>
          <view style="margin-left: 30rpx">{{ item.mobile }}</view>
        </view>
        <view class="address">{{ item.address + item.detail_address }}</view>
        <view class="flex" style="justify-content: flex-end; margin-top: 20rpx">
          <view class="flex" style="margin-right: 30rpx" @click="gochang">
            <image src="../../static/icon/change.png" mode="aspectFill" style="width: 32rpx; height: 32rpx; margin-right: 12rpx"></image>
            <view @click.stop="gochang(item.id, item)">修改</view>
          </view>
          <view class="flex">
            <image src="../../static/icon/delblack.png" mode="aspectFill" style="width: 32rpx; height: 32rpx; margin-right: 12rpx"></image>
            <view @click.stop="deladdrss(item.id)">删除</view>
          </view>
        </view>
      </view>
    </view>
    <view class="addaddress" @click="goaddaddress">新增上门地址</view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      list: [] // 列表
    };
  },
  methods: {
    // 获取地址列表
    async gtelist() {
      const res = await uni.$http.post('/address/list');
      console.log('地址列表', res);
      this.list = res.data.data.list;
    },
    // 删除地址
    async deladdrss(id) {
      const res = await uni.$http.post('/address/del', {
        address_id: id
      });
      if (res.data.code == 1) {
        this.gtelist();
        return uni.showToast({
          title: res.data.msg,
          icon: 'none'
        });
      }
    },
    // 修改上门地址
    gochang(id, item) {
      uni.redirectTo({
        url: '/parents/changeaddress/changeaddress?detail=' + JSON.stringify(item)
      });
    },
    // 添加上门地址
    goaddaddress() {
      uni.redirectTo({
        url: '/parents/addaddress/addaddress'
      });
    },
    // 跳转到下单页面
    goorderdetail(item) {
      const pages = getCurrentPages();
      if (pages[pages.length - 2].route == 'parents/skyuyue/skyuyue') {
        uni.redirectTo({
          url: '/parents/skyuyue/skyuyue?data=' + JSON.stringify(item)
        });
      } else if (pages[pages.length - 2].route == 'parents/jixuyuyue/jixuyuyue') {
        uni.redirectTo({
          url: '/parents/jixuyuyue/jixuyuyue?data=' + JSON.stringify(item)
        });
      } else {
        uni.redirectTo({
          url: '/parents/skyuyue/skyuyue?data=' + JSON.stringify(item)
        });
      }
    }
  },
  onLoad() {
    // 获取地址列表
    this.gtelist();
  }
};
</script>

<style lang="scss" scoped>
.container {
  box-sizing: border-box;
  padding: 30rpx 20rpx;
  padding-bottom: 200rpx;
  .flex {
    display: flex;
    align-items: center;
  }
  .list {
    .listitem {
      box-sizing: border-box;
      width: 710rpx;
      margin-bottom: 20rpx;
      padding: 30rpx;
      background: #ffffff;
      box-shadow: 0rpx 0rpx 8rpx 2rpx rgba(213, 213, 213, 0.28);
      border-radius: 20rpx 20rpx 20rpx 20rpx;
      .address {
        box-sizing: border-box;
        font-family: PingFang SC, PingFang SC;
        font-weight: 500;
        font-size: 24rpx;
        color: #333333;
        margin-top: 14rpx;
        padding-bottom: 30rpx;
        border-bottom: 2rpx solid #f1f1f1;
        // width: 550rpx;
        // overflow: hidden;
        // white-space: nowrap;
        // text-overflow: ellipsis;
      }
    }
  }
  .addaddress {
    box-sizing: border-box;
    position: fixed;
    bottom: 60rpx;
    width: 690rpx;
    height: 90rpx;
    text-align: center;
    line-height: 90rpx;
    background-color: #3553e8;
    color: #fff;
    border-radius: 100rpx;
  }
}
</style>
<style>
page {
  background-color: #f8f8f8;
}
</style>
